package leetcode.leetcode_128;

import java.util.HashMap;
import java.util.HashSet;

class Solution {
    public int longestConsecutive(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            set.add(nums[i]);
        }
        int ans =0;
        for (int cur : set){

            if (set.contains(cur-1)){
                continue;
            }
            int y = cur+1;
            while(set.contains(y)){
                y++;
            }
            ans = Math.max(ans,y-cur);
        }
        return ans;
    }
}